package com.example.myblog1_0.controller;

import com.example.myblog1_0.service.ArticleService;
import com.example.myblog1_0.service.CategoryService;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: xc
 * @Date: 2018/12/21 19:36
 * @Description:
 **/
@RestController
public class CategoryController {
    @Autowired
    CategoryService categoryService;
    @Autowired
    ArticleService articleService;
    @GetMapping("/findCategoriesName")
    public JSONArray findCategoriesName(){
        return categoryService.findCategoriesName();
    }

    @GetMapping("/findCategoriesNameAndArticleNum")
    public JSONObject findCategoriesNameAndArticleNum(){
        return categoryService.getArticleNameAndNum();
    }
    @GetMapping("/getCategoryArticle")
    public JSONObject getCategoryArticle(@RequestParam("category") String category, @RequestParam("rows") int rows, @RequestParam("pageNum") int pageNum){

        return articleService.getArticlePartInfoByCategory(category,rows,pageNum);
    }
}
